package com.example.demo.controller;

import com.example.demo.entity.*;
import com.example.demo.service.AlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/alarm")
public class AlarmController {

    @Autowired
    private AlarmService alarmService;

    @PostMapping("/receive")
    public ResponseEntity<?> receiveAlarm(@Valid @RequestBody AlarmData alarmData) {
        try {
            alarmService.processAlarmData(alarmData);
            return ResponseEntity.ok().body("报警数据接收成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("报警数据处理失败: " + e.getMessage());
        }
    }
}    